package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ArticleConfigService;
import com.heima.article.service.ArticleHomeService;
import com.heima.model.article.dto.ArticleDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.CommetStatusDtos;
import com.heima.model.wemedia.dtos.CommentSelectDto;
import com.heima.model.wemedia.dtos.WeMediaCommentDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleClient implements IArticleClient {
    @Autowired
    private ArticleHomeService articleHomeService;

    @Autowired
    private ArticleConfigService articleConfigService;

    @Override
    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return articleHomeService.saveOrUpdateArticle(dto);
    }

    @Override
    @PostMapping("/comment")
    public PageResponseResult selectComment(WeMediaCommentDto dto) {
        return articleHomeService.findComments(dto);
    }

    @Override
    @PostMapping("/update_comment_status")
    public ResponseResult updateArticleConfig(@RequestBody CommetStatusDtos dto) {
        return articleConfigService.UpdateByArticleIdIsComment(dto)?ResponseResult.okResult(200,"成功"):ResponseResult.errorResult(500,"失败");
    }
}
